<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<script type="application/javascript" src="js/jquery-1.12.4.js"></script>
<script>
    $(doucument).ready(function () {
        $("#name").blur(function () {
            var  name = this.value;
            if (name ==null&&name ==""){
                $("#nameDiv").html("用户名不能为空！")
            }else {
                $.ajax({
                    url:"userServlet",   //请求的URL
                    type :"GET",            //请求的方式
                    data :"name"+name,      //请求的参数
                    dataType :"wext",
                    success : function (date) { //相应成功
                        if (date == "true") {
                            $("#nameDiv").html("用户名不能为空");
                        } else {
                            $("#nameDiv").html("用户名可以使用" );
                        }
                    }
                })
            }
        })
    })
</script>
<body>

<from cation="" id="from1">
    <table>
        <tr>
            <td>用户名</td>
            <td><input type="text" name="name" id="name"
                       onblur="validate();"/>&nbsp;<font color="#c00fff">*</font></td>
            <td>
                <div id="nameDiv" name="nameDiv" style="display:inline"></div>
            </td>
        </tr>
    </table>
</from>
</body>
</html>